package com.oneraku.service.utils;

import com.oneraku.service.exceptions.InfoException;
import org.springframework.util.StringUtils;

/**
 * @Author: hui.ren@huberbuy.com
 * @Date: 2020/3/10 17:14
 */
public class Const {
    public static final Long expire = 30 * 60 * 1000L;

    public static final Long EXPIRE_VERIFY = 10 * 60 * 1000L;
    /**
     * 手机正则
     */
    public static final String mobilePattern = "^[1](([3][0-9])|([4][5,7,9])|([5][0-9])|([6][6])|([7][3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$";
    /**
     * 邮箱正则
     */
    public static final String mailPattern = "^[A-Za-z0-9\\u4e00-\\u9fa5]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
    /**
     * 验证码-通过手机号修改密码
     */
    public static final String VerifyCodeMobilePassword = "VerifyCodeMobilePassword";
    /**
     * 验证码-通过邮箱修改密码
     */
    public static final String VerifyCodeMailPassword = "VerifyCodeMailPassword";
    /**
     * 验证码-换邮箱账号
     */
    public static final String VerifyCodeMailChange = "VerifyCodeMailChange";
    /**
     * 验证码-换绑手机号
     */
    public static final String VerifyCodeMobileChange = "VerifyCodeMobileChange";



    public static void checkVerifyCodeValid(String verifyType){
        if(StringUtils.isEmpty(verifyType)){
            throw new InfoException("验证码类型未知");
        } else if(VerifyCodeMobilePassword.equals(verifyType)
                || VerifyCodeMailPassword.equals(verifyType)
                || VerifyCodeMailChange.equals(verifyType)
                || VerifyCodeMobileChange.equals(verifyType)
        ){
        }  else {
            throw new InfoException("验证码类型未知");
        }
    }
}
